<template>
  <div>
    <Content style="width:90%">
      <Form :label-width="140">
        <FormItem label="上级分类" required>
          <Input v-model="supCategory.categoryName" disabled />
        </FormItem>
        <FormItem label="分类名称" required>
          <Input v-model="dataForm.categoryName" placeholder="请输入分类名称" />
        </FormItem>
        <FormItem label="分类编码" required>
          <Input v-model="dataForm.categoryCode" placeholder="请输入分类编码" />
        </FormItem>
        <FormItem label="排序" required>
          <InputNumber :min="1" v-model="dataForm.sortIndex" placeholder="请输入排序"></InputNumber>
        </FormItem>
        <FormItem label="交易模式" required>
          <RadioGroup v-model="dataForm.tradeMode">
            <Radio :label="0" :disabled="categoryDisabled"><span>线上</span></Radio>
            <Radio :label="1" :disabled="categoryDisabled"><span>到店</span></Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="是否为店铺分类" required>
          <RadioGroup v-model="dataForm.navStatus">
            <Radio :label="1"><span>是</span></Radio>
            <Radio :label="0"><span>否</span></Radio>
          </RadioGroup>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="Submit">提交</Button>
        </FormItem>
      </Form>
    </Content>
  </div>
</template>
<script>
export default {
  name: "CategoryCreate",
  props: {
    supCategory: Object,
    callbank: Function
  },
  watch: {
    supCategory(val) {
      if(val.tradeMode >= 0) {
        this.dataForm.tradeMode = val.tradeMode
        this.categoryDisabled = true
      } else {
        this.dataForm.tradeMode = 0
        this.categoryDisabled = false
      }
    }
  },
  data() {
    return {
      dataForm: {
        navStatus: 0,
        tradeMode: 0,
        categoryType: 0,
        sortIndex: 1,
      },
      categoryDisabled: false
    }
  },
  created() {
    
  },
  methods: {
    Submit() {
      this.dataForm.categoryPid = this.supCategory.categoryId
      this.dataForm.categoryLevel = this.supCategory.categoryLevel + 1
      new this.$rest({
        gateway: 'agroerp',
        service: "agroerp-shop",
        url: "/v1.0/category",
        data: {
          pojo: this.dataForm
        },
        action: (res) => {
          if (res.data.code === 20000) {
            this.$Message.success({
              content: '新增成功'
            })
            this.callbank()
          } else {
            this.$Message.error(res.data.msg)
          }
        },
      }).post()
    }
  }
}
</script>